<?php

/**
 * This is the model class for table "form".
 */
require_once(dirname(__FILE__).'/base/FormBase.php');
class Form extends FormBase
{
    const STATUS_DEACTIVE = 0, STATUS_ACTIVE = 1;
    
    public function relations(){
        return array(
            'elements' => array(self::HAS_MANY, 'FormElement', 'form_id', 'order' => 'position asc'),
            'contentType' => array(self::BELONGS_TO, 'ContentType', 'content_id'),
        );
    }
    
    public function getStatusOptions()
    {
        return array(
            self::STATUS_DEACTIVE => 'Deactive',
            self::STATUS_ACTIVE => 'Active',
        );
    }
    
    public function getStatusText()
    {
        $options = $this->getStatusOptions();
        return isset($options[$this->status]) ? $options[$this->status] : Yii::t('app', 'Unknown {att}', array('{att}'=>$this->status));
    }

    public function hasFileField()
    {
        $criteria = new CDbCriteria;
        $criteria->compare('form_id', $this->id);
        $criteria->compare('type', 'file');
        return FormElement::model()->exists($criteria);
    }
}